home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / system / linux_bo / netboot.zoo / arp.c next >
Encoding:
C/C++ Source or Header  |  1993-05-04  |  1.5 KB  |  60 lines

  1. #include "protocol.h"
  2. #include "bootinc.h"
  3.  
  4. /* Originally part of NCSA Telnet
  5.    Modified by Jamie Honan
  6. */
  7.  
  8. static ARPKT arp;
  9.  
  10. static int
  11. replyarp(uint8 *thardware, uint8 *tipnum)
  12. {
  13.     uint8 *pc;
  14.  
  15.     memcpy(&arp.d, &blankd, sizeof(DLAYER));
  16.     arp.d.type = EARP;            /* 0x0806 is ARP type */
  17.     arp.hrd = intswap(HTYPE);            /*  Ether=1 */
  18.     arp.pro = intswap(ARPPRO);        /* IP protocol=0x0800 */
  19.     arp.hln = DADDLEN;            /* Ethernet hardware length */
  20.     arp.pln = 4;                /* IP length=4 */
  21.     memcpy(arp.sha, nnmyaddr, DADDLEN);    /* sender's hardware addr */
  22.     memcpy(arp.spa, nnipnum, 4);        /* sender's IP addr */
  23.  
  24.     memcpy(arp.tha, thardware, DADDLEN);   /* who this goes to */
  25.     memcpy(arp.tpa, tipnum, 4);        /* requester's IP address */
  26.     arp.op=intswap(ARPREP);            /* byte swapped reply opcode */
  27.     memcpy(arp.d.dest, thardware, DADDLEN);    /* hardware place to send to */
  28.     dlayersend((DLAYER *)&arp,sizeof(arp));
  29.     return(0);        /* ARP ok */
  30. }
  31.  
  32. int arpinterpret(ARPKT *p)
  33. {
  34. /*
  35. *  check packet's desired IP address translation to see if it wants
  36. *  me to answer.
  37. */
  38.     if(p->op == intswap(ARPREQ) && (!memcmp(p->tpa, nnipnum, 4)))
  39.     { 
  40.         /* check for conflicting IP number with your own */
  41.         if(!memcmp(p->spa, nnipnum, 4))    
  42.         {
  43.              /* we are in trouble */
  44.              /* sender's ip is same as our's */
  45.             n_printf("Conflicting Ethernet address: %x:%x:%x:%x:%x:%x\n",
  46.                 p->sha[0],
  47.                 p->sha[1],
  48.                 p->sha[2],
  49.                 p->sha[3],
  50.                 p->sha[4],
  51.                 p->sha[5]);
  52.             return -102;
  53.         }
  54.         replyarp(p->sha, p->spa);        /* proper reply */
  55.     }
  56.     return(0);
  57. }
  58.  
  59.  
  60.